package com.heima.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2023/2/4 14:38
 * @Version 1.0
 */
@RestController
public class TestController {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @GetMapping("/send")
    public String send(){
        User user = new User();
        user.setUsername("zhangsan");
        user.setAge(22);

        kafkaTemplate.send("topic-news1", JSON.toJSONString(user));
        return "SUCCESS";
    }

}